FROM alpine:latest

MAINTAINER atompi <coder.atompi@gmail.com>

ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \
    && apk add --update openvpn iptables bash easy-rsa unzip zip \
    && cp -r /usr/share/easy-rsa /etc/openvpn/ \
    && ln -s /etc/openvpn/easy-rsa/easyrsa /usr/local/bin \
    && mkdir -p /etc/openvpn/server/certs /etc/openvpn/client/keys /openvpn-docker/users /var/log/openvpn \
    && chown openvpn:openvpn /var/log/openvpn \
    && rm -rf /tmp/* /var/tmp/* /var/cache/apk/* /var/cache/distfiles/*

COPY server.conf /etc/openvpn/server.conf
COPY sample.ovpn /etc/openvpn/client/sample.ovpn
COPY vars /etc/openvpn/easy-rsa/vars
COPY ovpn_adduser_by_pass.sh ovpn_adduser.sh ovpn_deluser.sh init.sh entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/*.sh \
    && mv /etc/openvpn /openvpn-docker/server

VOLUME /openvpn-docker/users
VOLUME /etc/openvpn

EXPOSE 1194/tcp 1194/udp

CMD ["entrypoint.sh"]
